//
//  OBRouter.m
//  XZXSchool
//
//  Created by obally on 2017/10/23.
//  Copyright © 2017年 obally. All rights reserved.
//

#import "OBRouter.h"
#import "OBMomentViewModel.h"
@interface OBRouter()
//从ViewModel到viewController的映射
@property(nonatomic,copy) NSDictionary *viewModelViewMappings;
@end
static OBRouter *shareIntance_ = nil;
@implementation OBRouter
+ (id)allocWithZone:(struct _NSZone *)zone
{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        shareIntance_ = [super allocWithZone:zone];
    });
    return shareIntance_;
}
- (id)copyWithZone:(NSZone *)zone
{
    return shareIntance_;
}
+ (instancetype)shareInstance
{
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        shareIntance_ = [[super alloc]init];
    });
    return shareIntance_;
}
- (OBViewController *)viewControllerForViewModel:(OBViewModel *)viewModel
{
    NSString *viewController = self.viewModelViewMappings[NSStringFromClass(viewModel.class)];
    NSParameterAssert([NSClassFromString(viewController) isSubclassOfClass:[OBViewController class]]);
    NSParameterAssert([NSClassFromString(viewController) instancesRespondToSelector:@selector(initWithViewModel:)]);
    return [[NSClassFromString(viewController) alloc]initWithViewModel:viewModel];
    
}
- (NSDictionary *)viewModelViewMappings
{
    return @{@"OBMomentViewModel":@"OBMomentViewController",//朋友圈
             };
}
@end
